package com.tmobile.phonebook.exceptions;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

public final class Errors {
	
	private static final Properties errors = new Properties();
	//private static final Errors instance = new Errors(); 
	
	//initialize errors from errors.properties file
	static {
		
		try {
			errors.load(new FileReader("error.properties"));
		} catch (FileNotFoundException e) {
			System.out.println("error.properties file not found in classpath:" + e.getLocalizedMessage());
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("IOException occured while initializing Errors:" + e.getLocalizedMessage());
			e.printStackTrace();
		} catch (Exception e) {
			System.out.println("Exception occured while initializing Errors:" + e.getLocalizedMessage());
			e.printStackTrace();
		}
	}
	
	private Errors ()
	{
		//avoid instantiation from outside the class
	}
	
	public static String getErrorMessage(int errorCode)
 	{
 		return errors.getProperty(new String(""+errorCode),"Unknown Error!");
 	}
 	
 	public static void printErrorMessage(int errorCode)
 	{
 		System.out.println(errors.getProperty(new String(""+errorCode),"Unknown Error!"));
 	}
}
